402-remove-k-digits.py
problem: ---
problem:

Given a non-negative integer num represented as a string, remove k digits from the number 
so that the new number is the smallest possible.

Note:
The length of num is less than 10002 and will be ≥ k.
The given num does not contain any leading zero.

Example 1:
Input: num = "1432219", k = 3
Output: "1219"
Explanation: Remove the three digits 4, 3, and 2 to form the new number 1219 which is the smallest.

Example 2:
Input: num = "10200", k = 1
Output: "200"
Explanation: Remove the leading 1 and the number is 200. Note that the output must not 
contain leading zeroes.

Example 3:
Input: num = "10", k = 2
Output: "0"
Explanation: Remove all the digits from the number and it is left with nothing which is 0.
---

-----------------------------------------------------------------------
bug_fixes: ---
bug_fixes:
Replace `{}` with `[]` on line 5.
Add `k -= 1` on line 13.
---

-----------------------------------------------------------------------
bug_desc: ---
bug_desc:
On line 5, stack is initialized as a dictionary, when it is used as a list later on. To fix this, set stack to a list ([]).
ON line 13, or after line 12, k is never updated. This causes an infinite loop, and can be fixed by decrementing k by 1 in each iteration of the loop.
---

-----------------------------------------------------------------------
line_no: ---
line_no:
5
---

-----------------------------------------------------------------------
buggy_code: ---
buggy_code:
1. class Solution:
2.     def removeKdigits(self, num: str, k: int) -> str:
3.         if k == num:
4.           return "0"
5.         stack = {}
6.         for i in range(len(num)):
7.           while k and stack and stack[-1] > num[i]:
8.             stack.pop()
9.             k -= 1
10.           stack.append(num[i])
11.         while k:
12.           stack.pop()
13. 
14.         index = 0
15.         while index < len(stack) and stack[index] == "0":
16.           index += 1
17.         return "0" if index == len(stack) else "".join(stack[index:])
---

-----------------------------------------------------------------------
correct_code: ---
correct_code:
1. class Solution:
2.     def removeKdigits(self, num: str, k: int) -> str:
3.         if k == num:
4.           return "0"
5.         stack = []
6.         for i in range(len(num)):
7.           while k and stack and stack[-1] > num[i]:
8.             stack.pop()
9.             k -= 1
10.           stack.append(num[i])
11.         while k:
12.           stack.pop()
13.           k -= 1
14.         
15.         index = 0
16.         while index < len(stack) and stack[index] == "0":
17.           index += 1
18.         return "0" if index == len(stack) else "".join(stack[index:])
---

-----------------------------------------------------------------------
